home *** CD-ROM | disk | FTP | other *** search
/ SGI Performance Co-Pilot 1.3 / SGI Performance Co-Pilot 1.3.iso / dist / dist6.4 / pcp.idb / usr / include / pcp / impl.h.z / impl.h
C/C++ Source or Header  |  1997-04-03  |  28KB  |  891 lines

  1. /*
  2.  * Copyright 1995, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  * 
  5.  * UNPUBLISHED -- Rights reserved under the copyright laws of the United
  6.  * States.   Use of a copyright notice is precautionary only and does not
  7.  * imply publication or disclosure.
  8.  * 
  9.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  10.  * Use, duplication or disclosure by the Government is subject to restrictions
  11.  * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  12.  * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  13.  * in similar or successor clauses in the FAR, or the DOD or NASA FAR
  14.  * Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  15.  * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  16.  * 
  17.  * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  18.  * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  19.  * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  20.  * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  21.  * GRAPHICS, INC.
  22.  *
  23.  * $Id: impl.h,v 2.50 1997/03/26 02:31:03 kenmcd Exp $
  24.  */
  25.  
  26. #ifndef _IMPL_H
  27. #define _IMPL_H
  28.  
  29. #include <unistd.h>
  30. #include <sys/types.h>
  31. #include <sys/param.h>
  32. #include <sys/time.h>
  33. #include <sys/socket.h>
  34. #include <netinet/in.h>
  35. #include <netdb.h>
  36. #include <ndbm.h>
  37. #include <time.h>
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. /*
  44.  * This defines the routines, macros and data structures that are used
  45.  * in the Performance Metrics Collection Subsystem (PMCS) below the
  46.  * PMAPI.
  47.  */
  48.  
  49. /* PMCD connections have to come here ... */
  50. #define SERVER_PORT 4321
  51.  
  52. /*
  53.  * Internally, this is how to decode a PMID!
  54.  */
  55. typedef struct {
  56.     int        pad:2;
  57.     unsigned int    domain:8;
  58.     unsigned int    cluster:12;
  59.     unsigned int    item:10;
  60. } _pmID_int;
  61.  
  62. /*
  63.  * Internally, this is how to decode a Instance Domain Identifier!
  64.  */
  65. typedef struct {
  66.     int        pad:2;
  67.     unsigned int    domain:8;        /* the administrative PMD */
  68.     unsigned int    serial:22;        /* unique within PMD */
  69. } _pmInDom_int;
  70.  
  71. /*
  72.  * internal structure of a PMNS node
  73.  */
  74. typedef struct pn_s {
  75.     struct pn_s    *parent;
  76.     struct pn_s    *next;
  77.     struct pn_s    *first;
  78.     struct pn_s    *hash;    /* used as "last" in build, then pmid hash synonym */
  79.     char    *name;
  80.     pmID    pmid;
  81. } _pmnsNode;
  82.  
  83. /* only used by pmnscomp ... */
  84. extern void _pmExportPMNS(_pmnsNode **, int *, _pmnsNode ***);
  85.  
  86. /* standard log file set up */
  87. extern FILE *_pmOpenLog(char *, char *, FILE *, int *);
  88. /* make _pmNotifyErr also add entries to syslog */
  89. extern void _pmSyslog(int);
  90. /* standard error, warning and info wrapper for syslog(3C) */
  91. extern void _pmNotifyErr(int, const char *, ...);
  92.  
  93. /*
  94.  * These ones are only for debugging and may not appear in the shipped
  95.  * libpmapi ...
  96.  */
  97. extern int    pmDebug;
  98. /* debug control bit fields */
  99. #define  DBG_TRACE_PDU        1    /* reserved for libpcp */
  100. #define  DBG_TRACE_FETCH    2
  101. #define  DBG_TRACE_PROFILE    4
  102. #define  DBG_TRACE_CONV        8
  103. #define  DBG_TRACE_CONTEXT    16
  104. #define  DBG_TRACE_INDOM    32
  105. #define  DBG_TRACE_PDUBUF    64
  106. #define  DBG_TRACE_LOG        128
  107. #define  DBG_TRACE_LOGMETA    256
  108. #define  DBG_TRACE_OPTFETCH    512
  109. #define  DBG_TRACE_AF        1024
  110. #define  DBG_TRACE_APPL0    2048    /* reserved for applications */
  111. #define  DBG_TRACE_APPL1    4096
  112. #define  DBG_TRACE_APPL2    8192
  113. #define  DBG_TRACE_PMNS        16384    /* more for libpcp */
  114. #define  DBG_TRACE_LIBPMDA    32768    /* libpmda */
  115. #define  DBG_TRACE_TIMECONTROL    65536    /* time control api */
  116.  
  117. extern void _pmDumpResult(FILE *, pmResult *);
  118. extern void _pmPrintStamp(FILE *, struct timeval *);
  119. extern void _pmFreeResultValues(pmResult *);
  120. extern char *_pmPDUTypeStr(int);
  121. extern void _pmDumpNameSpace(FILE *, int);
  122.  
  123. /*
  124.  * struct timeval is sometimes 2 x 64-bit ... we use a 2 x 32-bit format for
  125.  * PDUs, internally within libpcp and for (external) archive logs
  126.  */
  127. typedef struct {
  128.     __int32_t    tv_sec;        /* seconds since Jan. 1, 1970 */
  129.     __int32_t    tv_usec;    /* and microseconds */
  130. } _pmTimeval;
  131.  
  132. /*
  133.  * Logs and archives of performance metrics (not to be confused
  134.  * with diagnostic logs for error messages, etc.)
  135.  *
  136.  * _pmLogCtl    log control
  137.  * _pmLogTI    temporal index record
  138.  */
  139.  
  140. /*
  141.  * Hashed Data Structures for the Processing of Logs and Archives
  142.  */
  143. typedef struct _hashnode {
  144.     struct _hashnode    *next;
  145.     int            key;
  146.     void        *data;
  147. } _pmHashNode;
  148.  
  149. typedef struct {
  150.     int        nodes;
  151.     int        hsize;
  152.     _pmHashNode    **hash;
  153. } _pmHashCtl;
  154.  
  155. extern _pmHashNode *_pmHashSearch(int, _pmHashCtl *);
  156. extern int _pmHashAdd(int, void *, _pmHashCtl *);
  157. extern int _pmHashDel(int, void *, _pmHashCtl *);
  158.  
  159. /*
  160.  * External file and internal (below PMAPI) format for an archive label
  161.  */
  162. typedef struct {
  163.     int        ill_magic;    /* PM_LOG_MAGIC | log format version no. */
  164.     pid_t    ill_pid;        /* PID of logger */
  165.     _pmTimeval    ill_start;    /* start of this log */
  166.     int        ill_vol;        /* current log volume no. */
  167.     char    ill_hostname[MAXHOSTNAMELEN];    /* name of collection host */
  168.     char    ill_tz[40];    /* $TZ at collection host */
  169. } _pmLogLabel;
  170.  
  171. /*
  172.  * unfortunately, in this version, PCP archives are limited to no
  173.  * more than 2 Gbytes ...
  174.  */
  175. typedef __uint32_t    pm_off_t;
  176.  
  177. /*
  178.  * Temporal Index Record
  179.  */
  180. typedef struct {
  181.     _pmTimeval    ti_stamp;    /* now */
  182.     int        ti_vol;        /* current log volume no. */
  183.     pm_off_t    ti_meta;    /* end of meta data file */
  184.     pm_off_t    ti_log;        /* end of metrics log file */
  185. } _pmLogTI;
  186.  
  187. /*
  188.  * Log/Archive Control
  189.  */
  190. typedef struct {
  191.     int        l_refcnt;    /* number of contexts using this log */
  192.     char    *l_name;    /* external log base name */
  193.     FILE    *l_tifp;    /* temporal index */
  194.     FILE    *l_mdfp;    /* meta data */
  195.     FILE    *l_mfp;        /* current metrics log */
  196.     int        l_curvol;    /* current metrics log volume no. */
  197.     int        l_state;    /* (when writing) log state */
  198.     _pmHashCtl    l_hashpmid;    /* PMID hashed access */
  199.     _pmHashCtl    l_hashindom;    /* instance domain hashed access */
  200.     _pmHashCtl    l_hashrange;    /* ptr to first and last value in log for */
  201.                 /* each metric */
  202.     int        l_minvol;    /* (when reading) lowest known volume no. */
  203.     int        l_maxvol;    /* (when reading) highest known volume no. */
  204.     int        l_numseen;    /* (when reading) size of l_seen */
  205.     int        *l_seen;    /* (when reading) volumes opened OK */
  206.     _pmLogLabel    l_label;    /* (when reading) log label */
  207.     pm_off_t    l_physend;    /* (when reading) offset to physical EOF */
  208.                 /*                for last volume */
  209.     _pmTimeval    l_endtime;    /* (when reading) timestamp at logical EOF */
  210.     int        l_numti;    /* (when reading) no. temporal index entries */
  211.     _pmLogTI    *l_ti;        /* (when reading) temporal index */
  212. } _pmLogCtl;
  213.  
  214. /* l_state values */
  215. #define PM_LOG_STATE_NEW    0
  216. #define PM_LOG_STATE_INIT    1
  217.  
  218. /*
  219.  * Dump the current context (hostname + instance profile), for a
  220.  * particular instance domain
  221.  * If indom == PM_INDOM_NULL, then print all all instance domains
  222.  */
  223. extern void _pmDumpContext(FILE *, int, pmInDom);
  224.  
  225. /*
  226.  * translate a PMDA name into a path for a file that exists
  227.  * - uses /usr/pcp/lib and /var/pcp/lib toggling
  228.  * - support PMDA_PATH for relative filenames
  229.  */
  230. extern char *_pmFindPMDA(char *);
  231.  
  232. /*
  233.  * instance profile states
  234.  */
  235. #define PM_PROFILE_INCLUDE 0    /* include all, exclude some */
  236. #define PM_PROFILE_EXCLUDE 1    /* exclude all, include some */
  237.  
  238. /* Profile entry (per instance domain) */
  239. typedef struct {
  240.     pmInDom    indom;            /* instance domain */
  241.     int        state;            /* include all or exclude all */
  242.     int        instances_len;        /* length of instances array */
  243.     int        *instances;        /* array of instances */
  244. } _pmInDomProfile;
  245.  
  246. /* Instance profile for all domains */
  247. typedef struct {
  248.     int            state;            /* default global state */
  249.     int            profile_len;        /* length of profile array */
  250.     _pmInDomProfile    *profile;        /* array of instance profiles */
  251. } _pmProfile;
  252.  
  253. /*
  254.  * Dump the instance profile, for a particular instance domain
  255.  * If indom == PM_INDOM_NULL, then print all instance domains
  256.  */
  257. extern void _pmDumpProfile(FILE *, int, _pmProfile *);
  258.  
  259. /*
  260.  * Result structure for instance domain queries
  261.  * Only the PMD agents and pmcd need to know about this.
  262.  */
  263. typedef struct {
  264.     pmInDom    indom;        /* instance domain */
  265.     int        numinst;    /* may be 0 */
  266.     int        *instlist;    /* instance ids, may be NULL */
  267.     char    **namelist;    /* instance names, may be NULL */
  268. } _pmInResult;
  269. extern void _pmDumpInResult(FILE *, _pmInResult *);
  270.  
  271. /* instance profile methods */
  272. extern int _pmGetFd(void);
  273. extern _pmProfile *_pmCurProfile(void);
  274. extern int _pmProfileSetSent(void);
  275. extern void _pmFreeProfile(_pmProfile *);
  276. extern _pmInDomProfile *_pmFindProfile(pmInDom, _pmProfile *);
  277. extern int _pmInProfile(pmInDom, _pmProfile *, int);
  278. extern void _pmFreeInResult(_pmInResult *);
  279.  
  280. /*
  281.  * Control for connection to a PMCD
  282.  */
  283. typedef struct {
  284.     int        pc_refcnt;        /* number of contexts using this socket */
  285.     char    *pc_name;        /* host name */
  286.     int        pc_fd[2];        /* socket for comm with pmcd */
  287.                     /* ... -1 means no connection */
  288.     int        pc_timeout;        /* set if connect times out */
  289.     time_t    pc_again;        /* time to try again */
  290. } _pmPMCDCtl;
  291.  
  292. /*
  293.  * per context controls for archives and logs
  294.  */
  295. typedef struct {
  296.     _pmLogCtl        *ac_log;    /* global logging and archive control */
  297.     long        ac_offset;    /* fseek ptr for archives */
  298.     int            ac_vol;        /* volume for ac_offset */
  299.     int            ac_serial;    /* serial access pattern for archives */
  300.     _pmHashCtl        ac_pmid_hc;    /* per PMID controls for INTERP */
  301. } _pmArchCtl;
  302.  
  303. /*
  304.  * PMAPI context. We keep an array of these,
  305.  * one for each context created by the application.
  306.  */
  307. typedef struct {
  308.     int            c_type;        /* PM_CONTEXT_HOST, _ARCHIVE or _FREE */
  309.     int            c_mode;        /* current mode PM_MODE_* */
  310.     _pmPMCDCtl        *c_pmcd;    /* pmcd control for HOST contexts */
  311.     _pmArchCtl        *c_archctl;    /* log control for ARCHIVE contexts */
  312.     _pmTimeval        c_origin;    /* pmFetch time origin / current time */
  313.     int            c_delta;    /* for updating origin */
  314.     int            c_mux;        /* PM_COLL_NOW or PM_COLL_VCR */
  315.     int            c_sent[2];    /* profile has been sent to pmcd */
  316.     _pmProfile        *c_instprof;    /* instance profile */
  317. } _pmContext;
  318.  
  319. #define PM_CONTEXT_FREE        -1    /* special type */
  320. #define PM_COLL_NOW        0    /* pmcd */
  321. #define PM_COLL_VCR        1    /* pmvcr */
  322.  
  323. /* handle to _pmContext pointer */
  324. extern _pmContext *_pmHandleToPtr(int);
  325.  
  326. /*
  327.  * Protocol data unit support
  328.  */
  329. typedef struct {
  330.     int    len;        /* length of pdu_header + PDU */
  331.     int    type;        /* PDU type */
  332.     int    from;        /* pid of PDU originator */
  333. } _pmPDUHdr;
  334.  
  335. typedef int _pmPDU;
  336.  
  337. #define PDU_PROTOCOL_VERSION    1
  338.  
  339. /* ASCII PDU line buffer */
  340. #define ABUFSIZE 256
  341. extern char _pmAbuf[ABUFSIZE];
  342.  
  343. extern int _pmXmitPDU(int, _pmPDU *);
  344. extern int _pmXmitAscii(int, char *, int);
  345. extern int _pmGetPDU(int, int, int, _pmPDU * *);
  346. /* for _pmGetPDU */
  347. #define TIMEOUT_NEVER     0
  348. #define TIMEOUT_DEFAULT    -1
  349. #define GETPDU_ASYNC    -2
  350. extern int _pmRecvPDU(int, int, _pmPDU * *);    /* old interface to _pmGetPDU */
  351.  
  352. extern int _pmRecvLine(_pmPDU *, int, char *);
  353. extern int _pmGetFd(void);
  354. extern _pmPDU *_pmFindPDUBuf(int);
  355. extern void _pmPinPDUBuf(void *);
  356. extern int _pmUnpinPDUBuf(void *);
  357.  
  358. #define PDU_ERROR        0x7000
  359. #define PDU_RESULT        0x7001
  360. #define PDU_PROFILE        0x7002
  361. #define PDU_FETCH        0x7003
  362. #define PDU_DESC_REQ        0x7004
  363. #define PDU_DESC        0x7005
  364. #define PDU_INSTANCE_REQ    0x7006
  365. #define PDU_INSTANCE        0x7007
  366. #define PDU_TEXT_REQ        0x7008
  367. #define PDU_TEXT        0x7009
  368. #define PDU_CONTROL_REQ        0x700a
  369. #define PDU_DATA_X        0x700b
  370.  
  371. /*
  372.  * PDU encoding formats
  373.  */
  374. #define PDU_BINARY    0
  375. #define PDU_ASCII    1
  376.  
  377. extern int _pmSendError(int, int, int);
  378. extern int _pmDecodeError(_pmPDU *, int, int *);
  379. extern int _pmSendResult(int, int, pmResult *);
  380. extern int _pmDecodeResult(_pmPDU *, int, pmResult **);
  381. extern int _pmSendProfile(int, int, int, _pmProfile *);
  382. extern int _pmDecodeProfile(_pmPDU *, int, int *, _pmProfile **);
  383. extern int _pmSendFetch(int, int, int, _pmTimeval *, int, pmID *);
  384. extern int _pmDecodeFetch(_pmPDU *, int, int *, _pmTimeval *, int *, pmID **);
  385. extern int _pmSendDescReq(int, int, pmID);
  386. extern int _pmDecodeDescReq(_pmPDU *, int, pmID *);
  387. extern int _pmSendDesc(int, int, pmDesc *);
  388. extern int _pmDecodeDesc(_pmPDU *, int, pmDesc *);
  389. extern int _pmSendInstanceReq(int, int, _pmTimeval *, pmInDom, int, char *);
  390. extern int _pmDecodeInstanceReq(_pmPDU *, int, _pmTimeval *, pmInDom *, int *, char **);
  391. extern int _pmSendInstance(int, int, _pmInResult *);
  392. extern int _pmDecodeInstance(_pmPDU *, int, _pmInResult **);
  393. extern int _pmSendTextReq(int, int, int, int);
  394. extern int _pmDecodeTextReq(_pmPDU *, int, int *, int *);
  395. extern int _pmSendText(int, int, int, char *);
  396. extern int _pmDecodeText(_pmPDU *, int, int *, char **);
  397. extern int _pmSendControlReq(int, int, pmResult *, int, int, int);
  398. extern int _pmDecodeControlReq(_pmPDU *, int, pmResult **, int *, int *, int *);
  399. extern int _pmSendDataX(int, int, int, int, void *);
  400. extern int _pmDecodeDataX(_pmPDU *, int, int *, int *, void **);
  401.  
  402. #if _MIPS_SZLONG == 64
  403.  
  404. /*
  405.  * A pmValue contains the union of a 32-bit int and a pointer.  In the world
  406.  * of 64-bit pointers, a pmValue is therefore larger than in the 32-bit world.
  407.  * The structures below are used in all PDUs containing pmResults to ensure
  408.  * 32-bit and 64-bit programs exchanging PDUs can communicate.
  409.  * Note that a pmValue can only hold a 32-bit value in situ regardless of
  410.  * whether the pointer size is 32 or 64 bits.
  411.  */
  412.  
  413. typedef struct {
  414.     int            inst;        /* instance identifier */
  415.     union {
  416.     unsigned int    pval;        /* offset into PDU buffer for value */
  417.     int        lval;        /* 32-bit value in situ */
  418.     } value;
  419. } _pmValue_PDU;
  420.  
  421. typedef struct {
  422.     pmID        pmid;        /* metric identifier */
  423.     int            numval;        /* number of values */
  424.     int            valfmt;        /* value style */
  425.     _pmValue_PDU    vlist[1];    /* set of instances/values */
  426. } _pmValueSet_PDU;
  427.  
  428. #elif _MIPS_SZLONG == 32
  429.  
  430. /* In the 32-bit world, structures may be used in PDUs as defined */
  431.  
  432. typedef pmValue        _pmValue_PDU;
  433. typedef pmValueSet    _pmValueSet_PDU;
  434.  
  435. #else
  436. bozo - unknown _MIPS_SZLONG!!!;
  437. #endif
  438.  
  439. /*
  440.  * If you use help files created via "newhelp" and ndbm(3B), then
  441.  * this is the key you should use, i.e. dptr -> _pmHelpKey and
  442.  * dsize = sizeof(_pmHelpKey)
  443.  */
  444. typedef struct {
  445.     int        ident;        /* PMID or InDom */
  446.     int        type;
  447. } _pmHelpKey;
  448. /*
  449.  * The "type" field is PM_TEXT_ONELINE or PM_TEXT_HELP with one of
  450.  * the following "ident" qualifiers or'd in
  451.  */
  452. #define PM_TEXT_PMID    4
  453. #define PM_TEXT_INDOM    8
  454.  
  455. /*
  456.  * alternatively, open the ndbm file(s) with ndbm_open() and then
  457.  * use ...
  458.  */
  459. extern char *_pmGetText(DBM *, int, int);
  460.  
  461. /*
  462.  * Quick-and-dirty pool memory allocator ...
  463.  */
  464. extern void *_pmPoolAlloc(size_t);
  465. extern void _pmPoolFree(void *, size_t);
  466.  
  467. /*
  468.  * no mem today, my love has gone away ....
  469.  */
  470. extern void _pmNoMem(char *, size_t, int);
  471. #define PM_FATAL_ERR 1
  472. #define PM_RECOV_ERR 0
  473.  
  474. /*
  475.  * nodelock license check
  476.  */
  477. extern int _pmGetLicense(int, char *, int);
  478. extern int _pmGetLicenseCap(void);
  479. #define PM_LIC_COL    1
  480. #define PM_LIC_MON    2
  481. #define PM_LIC_PCP    4
  482. #define PM_LIC_WEB    8
  483. #ifdef DEBUG
  484. #define PM_LIC_DEV    16384    /* for development and testing */
  485. #endif
  486.  
  487. /*
  488.  * execution states ... PM_STATE_APPL means we are at or above the
  489.  * PMAPI in a state where PMAPI calls can safely be made ... PM_STATE_PMCS
  490.  * means we are in the PMCD, or a PMDA, or low-level PDU code, and
  491.  * PMAPI calls are a bad idea.
  492.  */
  493. extern int _pmState;
  494. #define PM_STATE_APPL    0
  495. #define PM_STATE_PMCS    1
  496.  
  497. /*
  498.  * program name, as used in _pmNotifyErr() ... default is "pcp"
  499.  */
  500. extern char    *pmProgname;
  501.  
  502. /* agent-PMCD PDU readiness codes */
  503. #define PMDA_STS_READY        -2048    /* PMDA willing and able to process PDUs */
  504. #define PMDA_STS_NOT_READY    -2049    /* PMDA unable to process PDUs */
  505.  
  506. /* map Unix errno values to PMAPI errors */
  507. extern int _pmMapErrno(int);
  508.  
  509. /*
  510.  * _pmLogInDom is used to hold the instance identifiers for an instance
  511.  * domain internally ... if multiple sets are observed over time, these
  512.  * are linked together in reverse chronological order
  513.  * -- externally we write these as
  514.  *    timestamp
  515.  *    indom        <- note, added wrt indom_t
  516.  *    numinst
  517.  *    inst[0], .... inst[numinst-1]
  518.  *    nameindex[0] .... nameindex[numinst-1]
  519.  *    string (name) table, all null-byte terminated
  520.  */
  521. typedef struct _indom_t {
  522.     struct _indom_t    *next;
  523.     _pmTimeval        stamp;
  524.     int            numinst;
  525.     int            *instlist;
  526.     char        **namelist;
  527. } _pmLogInDom;
  528.  
  529. /*
  530.  * record header in the metadata log file ... len (by itself) also is
  531.  * used as a trailer
  532.  */
  533. typedef struct {
  534.     int        len;    /* record length, includes header and trailer */
  535.     int        type;    /* see TYPE_* #defines below */
  536. } _pmLogHdr;
  537.  
  538. #define TYPE_DESC    1    /* header, pmDesc, trailer */
  539. #define TYPE_INDOM    2    /* header, _pmLogInDom, trailer */
  540.  
  541. extern void _pmLogPutIndex(_pmLogCtl *, _pmTimeval *);
  542.  
  543. extern char *_pmLogName(char *, int);
  544. extern FILE *_pmLogNewFile(char *, int);
  545. extern int _pmLogCreate(char *, char *, _pmLogCtl *);
  546. extern int _pmLogRead(_pmLogCtl *, int, FILE *, pmResult **);
  547. extern int _pmLogWriteLabel(FILE *, _pmLogLabel *);
  548. extern int _pmLogOpen(char *, _pmContext *);
  549. extern int _pmLogLoadMeta(_pmLogCtl *);
  550. extern void _pmLogClose(_pmLogCtl *);
  551.  
  552. extern int _pmLogPutDesc(_pmLogCtl *, pmDesc *);
  553. extern int _pmLogLookupDesc(_pmLogCtl *, pmID, pmDesc *);
  554. extern int _pmLogPutInDom(_pmLogCtl *, pmInDom, _pmTimeval *, int, int *, char **);
  555. extern int _pmLogGetInDom(_pmLogCtl *, pmInDom, _pmTimeval *, int **, char ***);
  556. extern int _pmLogLookupInDom(_pmLogCtl *, pmInDom, _pmTimeval *, char *);
  557. extern int _pmLogNameInDom(_pmLogCtl *, pmInDom, _pmTimeval *, int, char **);
  558.  
  559. extern int _pmLogPutResult(_pmLogCtl *, _pmPDU *);
  560. extern int _pmLogFetch(_pmContext *, int, pmID *, pmResult **);
  561. extern int _pmLogFetchInterp(_pmContext *, int, pmID *, pmResult **);
  562. extern void _pmLogSetTime(_pmContext *);
  563. extern void _pmLogResetInterp(_pmContext *);
  564.  
  565. extern int _pmLogChangeVol(_pmLogCtl *, int);
  566.  
  567. #include <dirent.h>
  568.  
  569. /* This is the directory where pmlogger creates the file containing the port
  570.  * number it is using.
  571.  */
  572. #define    PM_LOG_PORT_DIR        "/var/tmp/pmlogger"
  573.  
  574. /* The primary logger creates a symbolic link to its own port file
  575.  * in PM_LOG_PORT_DIR.  This is the name of the link.
  576.  */
  577. #define PM_LOG_PRIMARY_LINK    "primary"
  578.  
  579. /* The primary logger creates this file in PM_LOG_PORT_DIR containing the port
  580.  * number of the VCR control port
  581.  */
  582. #define PM_LOG_VCR_FILE        "vcr"
  583.  
  584. /* struct for maintaining information about pmlogger ports */
  585. typedef struct {
  586.     int        pid;        /* process id of logger */
  587.     int        port;        /* internet port for logger control */
  588.     char    *pmcd_host;    /* host pmlogger is collecting from */
  589.     char    *archive;    /* archive base pathname */
  590.     char    *name;        /* file name (minus dirname) */
  591. } _pmLogPort;
  592.  
  593. /* Returns control port info for a pmlogger given its pid.
  594.  * If pid == -1, get all pmloggers' control ports.
  595.  * Note: do NOT free any part of result returned via the parameter.
  596.  *
  597.  * _pmLogFindPort(char *hostname, int pid, _pmLogPort **result);
  598.  */
  599. extern int _pmLogFindPort(char *, int, _pmLogPort **);
  600.  
  601. #define PM_LOG_ALL_PORTS    -1    /* return ports for all pmloggers */
  602.  
  603. /* Logging Control */
  604. extern int _pmConnectLogger(char *, int);
  605.  
  606. #define PM_LOG_CONTROL_PORT    0    /* ports for primary pmlogger */
  607. #define PM_LOG_VCR_PORT        1
  608.  
  609. extern int _pmControlLog(int, pmResult *, int, int, int, pmResult **);
  610.  
  611. #define PM_LOG_OFF        0    /* state */
  612. #define PM_LOG_MAYBE        1
  613. #define PM_LOG_ON        2
  614.  
  615. #define PM_LOG_MANDATORY    11    /* control */
  616. #define PM_LOG_ADVISORY        12
  617. #define PM_LOG_ENQUIRE        13
  618.  
  619. /* macros for logging control values from _pmControlLog() */
  620. #define PMLC_SET_ON(val, flag) \
  621.     val = (val & ~0x1) | (flag & 0x1)
  622. #define PMLC_GET_ON(val) \
  623.     (val & 0x1)
  624. #define PMLC_SET_MAND(val, flag) \
  625.     val = (val & ~0x2) | ((flag & 0x1) << 1)
  626. #define PMLC_GET_MAND(val) \
  627.     ((val & 0x2) >> 1)
  628. #define PMLC_SET_AVAIL(val, flag) \
  629.     val = (val & ~0x4) | ((flag & 0x1) << 2)
  630. #define PMLC_GET_AVAIL(val) \
  631.     ((val & 0x4) >> 2)
  632. #define PMLC_SET_INLOG(val, flag) \
  633.     val = (val & ~0x8) | ((flag & 0x1) << 3)
  634. #define PMLC_GET_INLOG(val) \
  635.     ((val & 0x8) >> 3)
  636.  
  637. #define PMLC_SET_STATE(val, state) \
  638.     val = (val & ~0xf) | (state & 0xf)
  639. #define PMLC_GET_STATE(val) \
  640.     (val & 0xf)
  641.  
  642. /* 28 bits of delta, 32 bits of state */
  643. #define PMLC_MAX_DELTA    0x0fffffff
  644.  
  645. #define PMLC_SET_DELTA(val, delta) \
  646.     val = (val & 0xf) | (delta << 4)
  647. #define PMLC_GET_DELTA(val) \
  648.     (((val & ~0xf) >> 4) & PMLC_MAX_DELTA)
  649.  
  650. /* PDU_DATA_X subtypes exchanged between pmlc and pmlogger */
  651. #define PMLC_PDU_STATUS_REQ    1
  652. #define PMLC_PDU_STATUS        2
  653. #define PMLC_PDU_NEWVOLUME    3
  654. #define PMLC_PDU_SYNC        4
  655.  
  656. /*
  657.  * NOTE ... MAXHOSTNAMELEN is a bad choice here for ls_hostname[], as
  658.  *    it may vary on different hosts ... we use MAXHOST instead, and
  659.  *    size this to be the same as for IRIX, circa 5.3
  660.  */
  661. #define MAXHOST        64
  662.  
  663. /* pmlogger returns one of these when a status request is made */
  664. typedef struct {
  665.     _pmTimeval    ls_start;    /* start time for log */
  666.     _pmTimeval    ls_last;    /* last time log written */
  667.     _pmTimeval    ls_timenow;    /* current time */
  668.     int        ls_state;    /* state of log (from _pmLogCtl) */
  669.     int        ls_vol;        /* current volume number of log */
  670.     long long    ls_size;    /* size of current volume */
  671.     char    ls_hostname[MAXHOST];
  672.                 /* name of collection host */
  673.     char    ls_tz[40];    /* $TZ at collection host */
  674.     char    ls_tzlogger[40]; /* $TZ at pmlogger */
  675. } _pmLoggerStatus;
  676.  
  677.  
  678. /* reporting timezone */
  679. extern int _pmUseZone(const int);
  680. extern int _pmNewZone(const char *);
  681. extern int _pmNewContextZone(void);
  682. extern int _pmWhichZone(char **);
  683. extern char *_pmCtime(const time_t *, char *);
  684. extern struct tm *_pmLocaltime(const time_t *, struct tm *);
  685. extern time_t _pmMktime(struct tm *);
  686.  
  687. /* reverse ctime and time interval parsing */
  688. extern int _pmParseInterval(char *, struct timeval *, char **);
  689. extern int _pmParseCtime(char *, struct tm *, char **);
  690. extern int _pmConvertTime(struct tm *, struct timeval *, struct timeval *);
  691. extern int _pmParseTime(
  692.       char *, struct timeval *, struct timeval *,
  693.       struct timeval *, char **);
  694.  
  695. /* mainupulate internal timestamps */
  696. extern double _pmTimevalSub(_pmTimeval *, _pmTimeval *);
  697.  
  698. /* 32-bit file checksum */
  699. extern __int32_t _pmCheckSum(FILE *);
  700.  
  701. /* check for localhost */
  702. extern int _pmIsLocalhost(char *);
  703.  
  704. /* host:metric[instances] or archive/metric[instances] */
  705. typedef struct {
  706.     int         isarch;         /* source type: 0 -> live host, 1 -> archive */
  707.     char        *source;        /* name of source host or archive */
  708.     char        *metric;        /* name of metric */
  709.     int         ninst;          /* number of instances, 0 -> all */
  710.     char        *inst[1];       /* array of instance names */
  711. } _pmMetricSpec;
  712.  
  713. /* parsing of host:metric[instances] or archive/metric[instances] */
  714. extern int _pmParseMetricSpec(char *, int, char *, _pmMetricSpec **, char **);
  715. #define _pmFreeMetricSpec(p) free(p)
  716.  
  717. /*
  718.  * struct timeval manipulations
  719.  */
  720. extern double _timevalAdd(struct timeval *, struct timeval *);
  721. extern double _timevalSub(struct timeval *, struct timeval *);
  722.  
  723. /*
  724.  * interface to _pmGetPDU() controls
  725.  */
  726. extern int _pmMoreInput(int);
  727. extern void _pmNoMoreInput(int);
  728.  
  729. /*
  730.  * time control internal API
  731.  */
  732. #define PM_TCTL_PROTO_VERSION    1    /* protocol version number */
  733.  
  734. /* internal commands */
  735. #define PM_TCTL_ACK        16    /* used by pmTimeSendAck */
  736. #define PM_TCTL_INITIALIZE    17    /* used by pmTimeConnect */
  737.  
  738. #define PM_TCTL_MASTER_PATH    "/usr/pcp/bin/pmtime"
  739.  
  740. /* time control client */
  741. typedef struct {
  742.     int            toClient;    /* server sends socket */
  743.     int            fromClient;    /* server receive socket */
  744.     int            wantAck;    /* nonzero => ACK expected */
  745.     int            version;    /* protocol version used by the client */
  746.     pmTime        data;        /* client state data */
  747. } _pmTimeClient;
  748.  
  749. /* time control timezone */
  750. typedef struct {
  751.     char        *label;        /* label to name tz */
  752.     char        *tz;        /* env $TZ */
  753.     int            handle;        /* handle from _pmNewZone() */
  754. } _pmTimeZone;
  755.  
  756. /* time control state */
  757. typedef struct {
  758.     int            mode;        /* mode bitmap */
  759.     int            control;    /* control port (socket) */
  760.     char        *port;        /* NULL if standalone */
  761.     pmTime        data;        /* synchronized state */
  762.     int            numclients;    /* number of clients */
  763.     _pmTimeClient    *clients;    /* array of clients */
  764.     int            numtz;        /* number of timezones */
  765.     _pmTimeZone        *tz;        /* array of time zones */
  766. } _pmTimeState;
  767.  
  768. /* pdu structure for PM_TCTL_INITIALIZE */
  769. typedef struct {
  770.     int            version;    /* version number */
  771.     pmTime        params;        /* user's parameters */
  772. } _pmTimeInitPDU;
  773.  
  774. /*
  775.  * Create control port on the given named pipe, then bind and listen.
  776.  * This is for use by X11 widgets and the pmTimeMaster main program.
  777.  */
  778. extern int _pmTimeInit(char *, pmTime *); /* port, initState */
  779.  
  780. /* close control port, close and free all clients, free internal state */
  781. extern int _pmTimeClose(void);
  782.  
  783. /* get pointer to internal time control state (static in timecontrol.c) */
  784. extern int _pmTimeGetState(_pmTimeState **);
  785.  
  786. /* accept a new client, return err */
  787. extern int _pmTimeAcceptClient(int *, int *, pmTime *); /* toClient*, fromClient*, initparams */
  788.  
  789. /* initialize a new time control client on given sockets|pipe */
  790. extern int _pmTimeAddClient(int, int); /* toClient, fromClient */
  791.  
  792. /* find a client (keyed by it's send file descriptor) */
  793. extern _pmTimeClient *_pmTimeFindClient(int); /* fd */
  794.  
  795. /* add a new time control timezone */
  796. extern int _pmTimeAddTimezone(char *, char *); /* label, tz */
  797.  
  798. /* find a previously added timezone by it's label, return it's handle */
  799. extern int _pmTimeGetTimezone(char *);
  800.  
  801. /* delete and free a time control client (on given sndFd) */
  802. extern int _pmTimeDelClient(int);
  803.  
  804. /* send a time control command to all clients, return err or 0 */
  805. extern int _pmTimeBroadcast(int, pmTime *); /* cmd, data */
  806.  
  807. /*
  808.  * return the number of clients with pending ACKS.
  809.  * If timeout is non-NULL and there are acks pending,
  810.  * block in select until any client is ready.
  811.  */
  812. extern int _pmTimeAcksPending(struct timeval *); /* timeout */
  813. extern void _pmTimeSetHungClients(void);
  814.  
  815. /* low level time control PDU transmit */
  816. extern int _pmTimeSendPDU(int, int, pmTime *); /* fd, cmd, state */
  817.  
  818. /* low level time control PDU receive, returns recv'ed command */
  819. extern int _pmTimeRecvPDU(int, pmTime *); /* fd, state */
  820.  
  821. /* debug routines */
  822. extern char *_pmTimeCmdStr(int);
  823. extern char *_pmTimeStateStr(int);
  824. extern char *_pmTimeStr(pmTime *);
  825.  
  826. /*
  827.  * Interface Definitions for PMDA DSO Interface
  828.  * This is the original structure, kept for backwards compatibility.
  829.  * Use pmdaInterface and pmdaMain instead.
  830.  */
  831.  
  832. typedef struct {
  833.     int    domain;        /* set/return performance metrics domain id here */
  834.     struct {
  835.     unsigned int    version : 4;    /* protocol version */
  836.     unsigned int    flags : 24;    /* usage TBD */
  837.     } comm;        /* set/return communication and version info */
  838.     int    status;        /* return initialization status here */
  839.  
  840.     int        (*profile)(_pmProfile *prof);
  841.     int        (*fetch)(int numpmid, pmID pmidlist[], pmResult **result);
  842.     int        (*desc)(pmID pmid, pmDesc *desc);
  843.     int        (*instance)(pmInDom indom, int inst, char *name, 
  844.             _pmInResult **result);
  845.     int        (*text)(int ident, int type, char **buffer);
  846.     int        (*control)(pmResult *request, int control, int state, 
  847.                int rate);
  848.     int        (*store)(pmResult *result);
  849. } _pmPMDA;
  850.  
  851. void pmdaMainLoop(char *, int, int, _pmPMDA *, int (*)(void), void (*)(void));
  852.  
  853. /*
  854.  * record session support
  855.  */
  856. #define PM_REC_OFF    40
  857. #define PM_REC_BEGIN    41
  858. #define PM_REC_HOST    42
  859. #define PM_REC_ON    43
  860. #define PM_REC_DETACH    44
  861.  
  862. extern FILE *_pmRecordSetup(char *, char *, int);
  863. extern FILE *_pmRecordAddHost(char *);
  864. extern int _pmRecordControl(int);
  865. extern char *_pmRecordStatus(int);
  866.  
  867. /*
  868.  * Map PMAPI error codes between PCP 1.x and PCP 2.0 and vice versa
  869.  * -1000 is start of PCP 1.x errors
  870.  * 0xc0000000 assumes no more than 2**30 PCP 2.0 errors
  871.  * Examples  1.x     2.0
  872.  *           -1000   0x80000000
  873.  *           -1001   0x80000001
  874.  *           -1050   0x80000032
  875.  */
  876. #define PM_ERR_20_TO_1X(v) (v < 0 && v < 0xc0000000 ? -((v & 0x7fffffff)+1000) : v)
  877. #define PM_ERR_1X_TO_20(v) (v <= -1000 ? 0x80000000+(-(v+1000)) : v)
  878.  
  879. /*
  880.  * path to pmLaunch scripts
  881.  */
  882.  
  883. #define PM_LAUNCH_PATH    "/var/pcp/config/pmlaunch/"
  884. #define PM_LAUNCH_RC    "/var/pcp/config/pmlaunch/pmlaunchrc"
  885.  
  886. #ifdef __cplusplus
  887. }
  888. #endif
  889.  
  890. #endif /* _IMPL_H */
  891.